//
//  KSReviewRebutViewController.swift
//  Supermarket
//
//  Created by liuxm on 2017/9/25.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

/// 驳回原因
class KSReviewRebutViewController: KSBaseViewController {

    @IBOutlet weak var rebutTV: UITextView!
    @IBOutlet weak var placeLabel: UILabel!
    @IBOutlet weak var numberLabel: UILabel!
    @IBOutlet weak var saveBtn: UIButton!
    var orderId: String = ""
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title = "驳回原因"
        
        self.saveBtn.setBackgroundImage(KSTools.createImageWithColor(color: KSColor.kColorMainRed), for: UIControlState.normal)
        self.saveBtn.setBackgroundImage(KSTools.createImageWithColor(color: KSColor.kColorButtonHighlight), for: UIControlState.highlighted)
        self.saveBtn.setBackgroundImage(KSTools.createImageWithColor(color: KSColor.kColorButtonDisabled), for: UIControlState.disabled)
    }

    @IBAction func saveEvent(_ sender: Any) {
        let parameters: [String : Any] = ["order_ids" : [orderId],"operate_state" : "-1","auditing_refuse_message" : rebutTV.text]
        self.request.requestIosOrderAuditing(parameters: parameters)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension KSReviewRebutViewController: UITextViewDelegate {
    
    func textViewDidBeginEditing(_ textView: UITextView) {
        self.placeLabel.isHidden = true
        self.saveBtn.isEnabled = true
    }
    
    func textViewDidEndEditing(_ textView: UITextView) {
        self.placeLabel.isHidden = !textView.text.isEmpty
    }
    
    func textViewDidChange(_ textView: UITextView) {
        numberLabel.text = "\(textView.text.count)/140"
        
    }
}
